package cashe;
import java.util.concurrent.atomic.AtomicReference;

public class SyncCache<K, V> implements ValueCache<K, V> {

	AtomicReference<K> key = new AtomicReference<K>();
	AtomicReference<V> val = new AtomicReference<V>();

	@Override
	synchronized public V get(K key) {
		if (key.equals(this.key.get())) {
			return val.get();
		} else {
			return null;
		}
	}

	@Override
	synchronized public void put(K key, V val) {
		this.key.set(key);
		this.val.set(val);

	}
}
